package com.example.administrator.hqq.adapter.discover;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.bean.MVPConventionBean;
import com.example.administrator.hqq.utils.BoldTextUtils;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2019/3/20 12:20
 * @remark:
 */
public class NewConventionGridAdapter extends BaseAdapter {
    private List<MVPConventionBean.DataBean> data;
    private Context context;

    public NewConventionGridAdapter(List<MVPConventionBean.DataBean> data, Context context) {
        this.data = data;
        this.context = context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("ViewHolder")
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view==null)
        {
            view = LayoutInflater.from(context).inflate(R.layout.new_convention_grid_item, null);
            viewHolder=new ViewHolder(view);
            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        Glide.with(context).load(data.get(i).getUrl()).into(viewHolder.topicImage);
        viewHolder.topicName.setText(data.get(i).getName());
        BoldTextUtils.BoldText(viewHolder.topicName);
        if (i==0||i==4||i==14)
        {
            viewHolder.topicBackground.setBackgroundColor(Color.parseColor("#e78758"));
        }else if (i==1||i==3||i==11)
        {
            viewHolder.topicBackground.setBackgroundColor(Color.parseColor("#67B4BB"));
        }else if (i==2||i==6||i==10)
        {
            viewHolder.topicBackground.setBackgroundColor(Color.parseColor("#D86C6C"));
        }else if (i==5||i==13)
        {
            viewHolder.topicBackground.setBackgroundColor(Color.parseColor("#DD8FA6"));
        }
        else if (i==7||i==9)
        {
            viewHolder.topicBackground.setBackgroundColor(Color.parseColor("#36709C"));
        }
        else if (i==8||i==12)
        {
            viewHolder.topicBackground.setBackgroundColor(Color.parseColor("#028A88"));
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.topic_image)
        ImageView topicImage;
        @BindView(R.id.topic_name)
        TextView topicName;
        @BindView(R.id.topic_background)
        RelativeLayout topicBackground;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
